<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2021/10/5
  Time: 13:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head lang="en">
    <title>用户注册</title>
    <script src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery.md5.js"></script>
    <link href="${pageContext.request.contextPath}/css/customer/register.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/common.css" rel="stylesheet">
    <link href="http://r1nxp2i0y.hn-bkt.clouddn.com/images/ico.png" rel="icon" type="image/x-ico"/>

</head>
<body>
<%--<div class="fail">${addMessage}</div>--%>
<div class="login-img">
    <div class="w1180">
        <div class="login">
            <div class="login-left">
                <img src="http://r1nxp2i0y.hn-bkt.clouddn.com/images/login-left1.jpg">
                <div class="login-left-text">
                    <div class="login-left-top">
                        <span></span>
                        "注册即享好礼"
                        <span></span>
                    </div>
                    <ul class="login-left-logo">
                        <li>
                            <span class="icon">减</span>
                            <p>登录就送优惠卷</p>
                        </li>
                        <li>
                            <span class="icon">￥</span>
                            <p>优惠满减满足你</p>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="register-right">
                <form class="registForm"  >
                    <div class="register-right-top">
                        <h3>新用户注册</h3>
                    </div>
                    <div class="register-right-top1">
                        <ul class="register-right-main">
                            <li>
                                <input name="custTel" class="username" type="text" placeholder="请输入你的手机号" maxlength="11">
                                <span class="username-msg"></span>
                            </li>
                            <li>
                                <input type="tel" id="verify_input"  placeholder="请输入验证码" maxlength="4">
                                <a href="javascript:void(0);" rel="external nofollow" title="点击更换验证码">
                                    <img class="verification" src="login1/getVerify" alt="更换验证码" height="36" width="170" onclick="getVerify(this);">
                                </a>
                                <%--                                <input class="verification" value="获得验证码" readonly>--%>
                            </li>
                            <li>
                                <input name="custPassword" class="register-password" type="password" placeholder="请输入密码" max="18">
                                <span class="register-password-msg"></span>
                            </li>
                            <li>
                                <input class="register-password2" type="password" placeholder="再次确认密码" max="18">
                                <span class="register-password-msg2"></span>
                            </li>
                        </ul>

                        <div class="register-right-text">
                            <p><input id = "must" type="checkbox"  checked="checked"/>
                                <span class="must-msg"></span>
                                我已阅读并同意
                                <a href="">《小橘租车会员注册协议》</a>和
                                <a href=""> 《小橘租车隐私政策》</a>
                            </p>
                        </div>
                        <div class="register-right-btn">
                            <input  type="button" value="注册" class="register-btn-popup">

                            <!--                    <a href="" title="注册" class="register-btn-popup">注册</a>-->
                        </div>
                        <div class="register-last">
                            已有帐号,
                            <a href="${pageContext.request.contextPath}/customer/login">立即登录</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/min.js"></script>
<script src="${pageContext.request.contextPath}/js/customer/jsencrypt.js"></script>
<script src="${pageContext.request.contextPath}/js/customer/register.js"></script>
<%--<script>--%>
<%--    $(".register-btn-popup").click(function () {--%>
<%--        var salt = "springbootdemo";--%>
<%--        var newPassword = $.md5($(".register-password").val()+ salt);--%>
<%--        $(".register-password").val(newPassword);--%>
<%--        var data = $(".registForm").serialize();--%>
<%--        console.log("data:"+data);--%>

<%--        $.post("${pageContext.request.contextPath}/register",--%>
<%--            data,--%>
<%--            function (result) {--%>
<%--            if(result.code==200){--%>
<%--                window.location.href="${pageContext.request.contextPath}/customer/login"--%>
<%--            }else {--%>
<%--                window.location.href="${pageContext.request.contextPath}/customer/register"--%>
<%--            }--%>

<%--            console.log("测试"+result)--%>
<%--            },--%>
<%--            "json"--%>
<%--        );--%>
<%--    })--%>
<%--</script>--%>
<script>
    function getVerify() {
        //获得验证码
        // $("#imgCode").on("click", function() {
        $(".verification").attr("src", 'login1/getVerify?' + Math.random());//jquery方式
        // });
    }
    var PUBLIC_KEY = '';
    $(".register-btn-popup").click(function () {
        var cheked = document.querySelector("#must").checked;
        console.log("试试"+cheked);
        if(cheked){
            $.ajax({
                type:"GET",
                url:"${pageContext.request.contextPath}/publickey",
                dataType:"json",
                success:function (result) {
                    console.log("。。。。。。。"+result)
                    PUBLIC_KEY = result.data;
                    console.log("前台密文"+PUBLIC_KEY);
                    var encrypt = new JSEncrypt();
                    encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + PUBLIC_KEY + '-----END PUBLIC KEY-----');
                    var password = $(".register-password").val();
                    var encrypted = encrypt.encrypt(password);
                    console.log("公钥:%o",PUBLIC_KEY);
                    console.log("加密后的数据:%o",encrypted);
                    var tel = $(".username").val();

                    var value =$("#verify_input").val();
                    $.ajax({
                        async: false,
                        type: 'post',
                        url: 'login1/checkVerify',
                        dataType: "json",
                        data: {
                            verifyInput: value
                        },
                        success: function (result) {
                            if (result) {

                                $.ajax({
                                    type:"POST",
                                    url: "${pageContext.request.contextPath}/register",
                                    data: {
                                        custTel:tel,
                                        custPassword:encrypted
                                    },
                                    success: function (result1) {
                                        if(result1.code==200){
                                            console.log("测试一次"+result1.code)
                                            window.location.href="${pageContext.request.contextPath}/customer/login"
                                        }else {
                                            window.location.href="${pageContext.request.contextPath}/customer/register"
                                        }
                                    },
                                    dataType:  "json"
                                });
                            } else {
                                alert("验证码错误");
                            }
                            // window.location.reload();
                            getVerify();
                        }
                    });
                    // if(checkPassword()&&checkUsername()){
                    //     $(".register-password").val(encrypted);
                    //     $(".registForm").submit();
                    // }
                }
            });
        }else if(cheked==false){
            document.querySelector(".must-msg").innerText="请勾选安全协议";
        }
    });
</script>
</body>
</html>
